package org.jeecg.modules.demo.yy.util;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import me.zhyd.oauth.log.Log;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.model.SysLoginModel;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Component
public class UserUtil {

    @Autowired
    private ISysUserService userService;

    public SysUser getSysUserByToken(HttpServletRequest req) {
        String userName = JwtUtil.getUserNameByToken(req);
        LambdaQueryWrapper<SysUser> qw = new LambdaQueryWrapper<>();
        qw.eq(SysUser::getUsername,userName);
        List<SysUser> list = userService.list(qw);
        if (list != null && list.size() == 1) {
            return list.get(0);
        }
        return null;
    }

}
